package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.infra.server.api.Result;

import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Api(value = "${table.controllerName}",tags="${table.comment!} 前端控制器")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Resource
    private ${table.serviceName} ${entity?uncap_first}Service;

    @ApiOperation(value = "增加或修改: ${table.comment!}", notes = "1")
    @PostMapping("/save")
    public Result saveOrUpdate(@RequestBody ${entity} ${entity?uncap_first}) {
        boolean a = ${entity?uncap_first}Service.saveOrUpdate(${entity?uncap_first});
        if(a) {
            return Result.ok().message("操作成功!");
        }
        return Result.error().message("操作失败，请重试!");
    }

    @ApiOperation(value = "根据id删除: ${table.comment!}", notes = "1")
    @GetMapping("/del/{id}")
    public Result del(@PathVariable("id") Integer id) {
        boolean a = ${entity?uncap_first}Service.removeById(id);
        if(a) {
            return Result.ok().message("操作成功!");
        }
        return Result.error().message("操作失败，请重试!");
    }

    @ApiOperation(value = "根据id查询: ${table.comment!}", notes = "1")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Integer id) {
        ${entity} ${entity?uncap_first} = ${entity?uncap_first}Service.getById(id);
        return Result.ok().data("data",${entity?uncap_first}).message("操作成功!");
    }

    @ApiOperation(value = "查询: ${table.comment!}", notes = "1")
    @GetMapping("/list")
    public Result list() {
        List<${entity}> list = ${entity?uncap_first}Service.list();
        return Result.ok().data("data",list).message("操作成功!");
    }
}
</#if>
